var { ReturnModel } = require('../libs/resmodel');
var { taskDone,taskList } = require('../services/tasktodo');
var {messageCount} = require('../services/message');

/**
* 待办处理
* @api {post} /tasktodo/done 待办处理
* @apiDescription 待办处理
* @apiName done
* @apiParam (参数) {String} id 待办id
* @apiParam (参数) {String} status 任务状态  // 0： 待办 1：通过  2：拒绝
* @apiParam (参数) {String} message 处理意见
* @apiSampleRequest /tasktodo/done
* @apiGroup tasktodo-我的待办
* @apiVersion 1.0.0
* @apiParamExample {json} Request-Example:
*     {
*       "id": 23,  // 待办id
*       "status": 1,  // 通过
*       "message": "可以解锁"  
*     }
* @apiSuccessExample {json} Success-Response:
*   HTTP/1.1 200 OK
*   {
*      "msg": "处理成功",
*      "code": 0
*   }
*/
async function done(req, res) {
    let result = await taskDone(req.body);
    res.json(new ReturnModel(result));
}
/**
* 待办列表
* @api {post} /tasktodo/list 待办列表
* @apiDescription 待办列表
* @apiName list
* @apiParam (参数) {String} pcode 用户code
* @apiSampleRequest /tasktodo/list
* @apiGroup tasktodo-我的待办
* @apiVersion 1.0.0
* @apiParamExample {json} Request-Example:
*     {
*       "pcode": "454395445867"
*     }
* @apiSuccessExample {json} Success-Response:
*   HTTP/1.1 200 OK
*   {
*      "data":[{
*          "name": "相册解锁", // 任务名称
*          "gdata": {
*              "nickname":"张三",
*              "avator":"xxxxxxxxxxxx"
*          }, // 申请用户信息
*          "updatetime": "2022-04-02 15:23:22", // 更新时间
*        }],
*      "msg": "获取成功",
*      "code": 0
*   }
*/
async function list(req, res) {
    let result = await taskList(req.body);
    res.json(new ReturnModel(result));
}
/**
* 获取消息数量
* @api {post} /tasktodo/count 获取消息数量
* @apiDescription 获取消息数量
* @apiName count
* @apiParam (参数) {String} pcode 用户code
* @apiSampleRequest /tasktodo/count
* @apiGroup tasktodo-我的待办
* @apiVersion 1.0.0
* @apiParamExample {json} Request-Example:
*     {
*       "pcode": "454395445867"
*     }
* @apiSuccessExample {json} Success-Response:
*   HTTP/1.1 200 OK
*   {
*      "data":{
*           tasktodo_count: 0, // 待办数量
*            access_count: 0, // 访客数量
*            myfans_count: 0, // 收藏我的数量
*            fanme_count: 0, // 我的收藏数量
*            myuser_count: 0, // 我的用户数量
*            lover_count: 0 // 情侣配对数量
*       },
*      "msg": "获取成功",
*      "code": 0
*   }
*/
async function count(req, res) {
    let result = await messageCount(req.body);
    res.json(new ReturnModel(result));
}

module.exports = function (app) {
    let base_url = '/api/tasktodo';

    app.post(base_url+'/done', done);
    app.post(base_url+'/list', list);
    app.post(base_url+'/count', count);
}
